Add helper function for prefix titles
authorjustbur <justin@burkett.cc>
Sun, 16 Aug 2015 22:19:30 +0000 (18:19 -0400)
committerjustbur <justin@burkett.cc>
Sun, 16 Aug 2015 22:19:30 +0000 (18:19 -0400)
which-key.el

index 444ec11ae81891674b9d3d235bda8f89be301390..4ecd4d30811168dd74955897002780d1dbcf1867 100644 (file)
@@ -478,6 +478,19 @@ addition KEY-SEQUENCE REPLACEMENT pairs) to apply."
         (setcdr (assq mode which-key-key-based-description-replacement-alist) mode-alist)
       (push (cons mode mode-alist) which-key-key-based-description-replacement-alist))))
 
+;;;###autoload
+(defun which-key-add-prefix-title (key-seq-str name &optional force)
+  "Add title for KEY-SEQ-STR given by TITLE.
+FORCE, if non-nil, will add the new title even if one already
+exists. KEY-SEQ-STR should be a key sequence string suitable for
+`kbd' and NAME should be a string."
+  (interactive)
+  (let ((key-seq-lst (listify-key-sequence (kbd key-seq-str))))
+    (if (and (null force)
+             (assoc key-seq-lst which-key-prefix-title-alist))
+        (message "which-key: Prefix title not added. A title exists for this prefix.")
+      (push (cons key-seq-lst name) which-key-prefix-title-alist))))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Functions for computing window sizes